package jbl.interceptot;

import javax.servlet.http.HttpSession;

import jbl.model.Tuser;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
  
public class LoginInterceptor extends AbstractInterceptor {  
  
    /**
	 * 登陆验证拦截器
	 */
	private static final long serialVersionUID = 1L;

	@Override  
    public String intercept(ActionInvocation invocation) throws Exception {  
  
		 HttpSession session = ServletActionContext.getRequest().getSession();  
		 Tuser user = (Tuser)session.getAttribute("user");  
        if(user == null){//错误,回到登录界面  
        	ServletActionContext.getRequest().setAttribute("tip", "您还没有登录!");
            return Action.LOGIN;  
        }else{  
        	System.out.println(user.getName() +"登录成功!");
            return invocation.invoke();  
        }  
    }  
}  

